package com.gack.business.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gack.business.dao.OrderDao;
import com.gack.business.service.StoreUniteInfoServiceInterface;
import com.gack.helper.common.AjaxJson;
import com.gack.helper.common.abstractobj.ApiController;

import io.swagger.annotations.ApiOperation;

/**
 * 
* @ClassName: StoreUniteInfoController 
* @Description: TODO(这里用一句话描述这个类的作用) 
* @author (ZhangXinYu)  
* @date 2018年6月7日 下午5:57:08 
* @version V1.0
 */
@RestController
@RequestMapping(ApiController.STOREUNITEINFO_URL)
public class StoreUniteInfoController {

	@Autowired
	private StoreUniteInfoServiceInterface storeUniteInfoService;
	
	@ApiOperation(value="查询所有门店统一信息",notes="查询所有门店统一信息")
	@PostMapping("getAllStoreUniteInfos")
	public AjaxJson getAllStoreUniteInfos(){
		AjaxJson ajaxJson = new AjaxJson();
		try{
			ajaxJson.setStatus(200).setSuccess(true).setData(storeUniteInfoService.getStoreUniteInfos());
		}catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setStatus(500).setSuccess(false).setData(null).setMsg("查询所有门店统一信息操作失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="分页查询所有门店统一信息",notes="分页查询所有门店统一信息")
	@PostMapping("getAllStoreUniteInfosByPage")
	public AjaxJson getAllStoreUniteInfosByPage(Integer currentPage,Integer pageSize){
		AjaxJson ajaxJson = new AjaxJson();
		try{
			ajaxJson.setStatus(200).setSuccess(true).setData(storeUniteInfoService.getStoreUniteInfos(currentPage, pageSize));
		}catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setStatus(500).setSuccess(false).setData(null).setMsg("分页查询所有门店统一信息操作失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="添加门店统一信息",notes="添加门店统一信息")
	@PostMapping("addStoreUniteInfo")
	public AjaxJson addStoreUniteInfo(String userid,String key,String value){
		AjaxJson ajaxJson = new AjaxJson();
		try{
			ajaxJson.setStatus(200).setSuccess(true).setData(storeUniteInfoService.addStoreUniteInfo(userid,key, value));
		}catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setStatus(500).setSuccess(false).setData(null).setMsg("添加门店统一信息操作失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="修改门店统一信息",notes="修改门店统一信息")
	@PostMapping("updateStoreUniteInfo")
	public AjaxJson updateStoreUniteInfo(String userid,String id,String value){
		AjaxJson ajaxJson = new AjaxJson();
		try{
			ajaxJson.setStatus(200).setSuccess(true).setData(storeUniteInfoService.updateStoreUniteInfo(userid,id, value));
		}catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setStatus(500).setSuccess(false).setData(null).setMsg("修改门店统一信息操作失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="删除门店统一信息",notes="删除门店统一信息")
	@PostMapping("dealStoreUniteInfo")
	public AjaxJson dealStoreUniteInfo(String userid,String id){
		AjaxJson ajaxJson = new AjaxJson();
		try{
			ajaxJson.setStatus(200).setSuccess(true).setData(storeUniteInfoService.dealStoreUniteInfo(userid,id));
		}catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setStatus(500).setSuccess(false).setData(null).setMsg("删除门店统一信息操作失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="通过key值删除门店统一信息",notes="通过key值删除门店统一信息")
	@PostMapping("dealStoreUniteInfoByKey")
	public AjaxJson dealStoreUniteInfoByKey(String userid,String key){
		AjaxJson ajaxJson = new AjaxJson();
		try{
			ajaxJson.setStatus(200).setSuccess(true).setData(storeUniteInfoService.dealStoreUniteInfoByKey(userid,key));
		}catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setStatus(500).setSuccess(false).setData(null).setMsg("删除门店统一信息操作失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="查询门店统一信息",notes="查询门店统一信息")
	@PostMapping("getStoreUniteInfo")
	public AjaxJson getStoreUniteInfo(String id){
		AjaxJson ajaxJson = new AjaxJson();
		try{
			ajaxJson.setStatus(200).setSuccess(true).setData(storeUniteInfoService.getStoreUniteInfo(id));
		}catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setStatus(500).setSuccess(false).setData(null).setMsg("查询门店统一信息操作失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="通过key值查询门店统一信息",notes="通过key值查询门店统一信息")
	@PostMapping("getStoreUniteInfoByKey")
	public AjaxJson getStoreUniteInfoByKey(String key){
		AjaxJson ajaxJson = new AjaxJson();
		try{
			ajaxJson.setStatus(200).setSuccess(true).setData(storeUniteInfoService.getStoreUniteInfoByKey(key));
		}catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setStatus(500).setSuccess(false).setData(null).setMsg("查询门店统一信息操作失败");
		}
		return ajaxJson;
	}
	@Autowired
	OrderDao dao;
	
	@ApiOperation(value="通过key值查询门店统一信息",notes="通过key值查询门店统一信息")
	@PostMapping("testaa")
	public AjaxJson getStoreUniteInfoByKey1(String key){
		AjaxJson ajaxJson = new AjaxJson();
		try{
			ajaxJson.setStatus(200).setSuccess(true).setData(dao.findAllOrder("0", "0", null, 0, 0, 1));
		}catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setStatus(500).setSuccess(false).setData(null).setMsg("查询门店统一信息操作失败");
		}
		return ajaxJson;
	}
	
}
